package com.baymax.test.scene

import android.app.Application
import android.content.ComponentCallbacks
import android.content.Context
import android.content.ContextWrapper
import android.content.res.Configuration
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.core.content.ContentProviderCompat.requireContext
import androidx.lifecycle.HasDefaultViewModelProviderFactory
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.SavedStateViewModelFactory
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelStore
import androidx.lifecycle.ViewModelStoreOwner
import androidx.lifecycle.lifecycleScope
import androidx.savedstate.SavedStateRegistry
import androidx.savedstate.SavedStateRegistryController
import androidx.savedstate.SavedStateRegistryOwner
import com.airbnb.mvrx.MavericksView
import com.airbnb.mvrx.MavericksViewInternalViewModel
import com.baymax.test.scene.life.LifeLogger
import com.bytedance.scene.ktx.requireNavigationScene
import kotlinx.coroutines.CoroutineScope
import org.koin.core.module._factoryInstanceFactory
import kotlin.coroutines.CoroutineContext

abstract class BaseScene : com.bytedance.scene.Scene(), ComponentCallbacks,
    CoroutineScope, MavericksView ,LifecycleOwner  {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        lifecycle.addObserver(LifeLogger)

    }

    companion object {
        const val TAG = "BaseScene_Debug"
    }


    override fun onLowMemory() {

    }

    override fun onConfigurationChanged(newConfig: Configuration) {
    }


    override val coroutineContext: CoroutineContext = lifecycleScope.coroutineContext


    override val mavericksViewInternalViewModel: MavericksViewInternalViewModel
        get() = ViewModelProvider(
            requireNavigationScene(),
            SavedStateViewModelFactory(
                requireNavigationScene().requireActivity().application,
                owner = (requireActivity() as ComponentActivity),
                defaultArgs = this.arguments
            )
        ).get(
            MavericksViewInternalViewModel::class.java
        )

    override fun invalidate() {

    }

//    override val lifecycle: BaseScene = this


}